import { Service } from "cl-admin";
import BaseService from "@/service/base";
@Service("customer")
class Customer extends BaseService {
	// 客户列表
	mycus({ wechat_join_time, add_time, size, bra_id = [], ...args }) {
		let params = {
			search_type: 0,
			pagesize: size,
			bra_id: bra_id?.join?.(),
			...args
		};
		if (wechat_join_time && wechat_join_time.length) {
			params.wechat_join_type = 99;
			params.wechat_join_btime = wechat_join_time[0];
			params.wechat_join_etime = wechat_join_time[1];
		}
		if (add_time && add_time.length) {
			params.add_btime = add_time[0];
			params.add_etime = add_time[1];
		}
		return this.$get("/mycus", { params }).then(res => {
			return {
				list: res.data,
				pagination: {
					...params,
					size,
					total: res.total
				}
			};
		});
	}
	lists({ wechat_join_time, add_time, size, ...args }) {
		let params = {
			search_type: 0,
			pagesize: size,
			...args
		};
		if (wechat_join_time && wechat_join_time.length) {
			params.wechat_join_type = 99;
			params.wechat_join_btime = wechat_join_time[0];
			params.wechat_join_etime = wechat_join_time[1];
		}
		if (add_time && add_time.length) {
			params.add_btime = add_time[0];
			params.add_etime = add_time[1];
		}
		return this.$get("/lists", { params }).then(res => {
			return {
				list: res.data ?? [],
				pagination: {
					...params,
					size,
					total: res.total
				}
			};
		});
	}

	// 查找客户
	searchCus(params) {
		return this.$get('/searchcus', { params })
	}
	//获取企业微信码
	getEnterpriseWx(){
		return this.$get("/getWorkwechatModelList");
	}
	// 客户列表
	/**
	 *
	 * search_type: 0, //搜索类型(0-全部 ,1-手机,2-客户名称,4-微信)
	 * search_content: "", //搜索名字
	 * biz_id: "", //事业部
	 * bra_id: "",
	 * company_id: "",
	 * dept_id: "", //门店
	 * id_ascr_dept: "", //所属部门
	 * id_ascr_op: "", //所属人
	 * id_add_dept: "", //创建部门
	 * id_add_op: "", //创健人
	 * source_id: "", //来源id
	 * is_zjs: "", //是否转介绍 1是 2不是
	 * is_rest: "", //1分期  2没分期
	 * is_deposit: "", //1下了定金  0没下定金
	 * status: "",
	 * add_type: 99,
	 * add_time: [], //创建时间
	 * add_btime: "", //创建时间开始
	 * add_etime: "", //创建时间结束
	 * add_deposit_type: 99,
	 * add_deposit_time: [], //首次下定日期
	 * add_deposit_btime: "", //首次下定日期开始
	 * add_deposit_etime: "", //首次下定日期结束
	 * last_shop_type: 99,
	 * last_shop_time: [], // 最近到店日期
	 * last_shop_btime: "", //最近到店日期开始
	 * last_shop_etime: "", //最近到店日期结束
	 * wechat_join_type: 99,
	 * wechat_join_time: [], //加微日期
	 * wechat_join_btime: "", //加微日期开始
	 * wechat_join_etime: "", //加微日期结束
	 * first_shop_type: 99,
	 * first_shop_time: [], //首次日期
	 * first_shop_begin: "", //首次日期开始
	 * first_shop_end: "", //首次日期结束
	 * pay_power_section: [0, 15000], // 消费能力范围
	 * pay_power_start: "", //消费能力范围开始
	 * pay_power_end: "" //消费能力范围结束
	 */
	page({
		add_time,
		add_deposit_time,
		last_shop_time,
		first_shop_time,
		wechat_join_time,
		pay_power_section,
		size,
		bra_id = [],
		...args
	}) {
		let params = {
			search_type: 0,
			pagesize: size,
			bra_id: bra_id.join(),
			...args
		};
		if (add_time && add_time.length) {
			params.add_btime = add_time[0];
			params.add_etime = add_time[1];
		}
		if (add_deposit_time && add_deposit_time.length) {
			params.add_deposit_btime = add_deposit_time[0];
			params.add_deposit_etime = add_deposit_time[1];
		}
		if (last_shop_time && last_shop_time.length) {
			params.last_shop_btime = last_shop_time[0];
			params.last_shop_etime = last_shop_time[1];
		}
		if (first_shop_time && first_shop_time.length) {
			params.first_shop_begin = first_shop_time[0];
			params.first_shop_end = first_shop_time[1];
		}
		if (wechat_join_time && wechat_join_time.length) {
			params.wechat_join_btime = wechat_join_time[0];
			params.wechat_join_etime = wechat_join_time[1];
		}
		// if (pay_power_section && pay_power_section.length) {
		// 	params.pay_power_start = pay_power_section[0];
		// 	params.pay_power_end = pay_power_section[1];
		// }
		return this.$get("/conlists", { params }).then(res => {
			return {
				list: res.data,
				pagination: {
					...params,
					size,
					total: res.total
				}
			};
		});
	}
	detail(params) {
		return this.$get("/getcusinfo", { params });
	}
	// 新增
	add(params) {
		return this.$post("/packageAdd", params);
	}
	// 更新，包含 id
	update(params) {
		return this.$post("/edit", params);
	}
	// 删除，ids = [1, 2, 3]
	del(params) {
		return this.$get("/del", { params });
	}
	// 积分列表
	scorelist(params) {
		return this.$get("/scorelist", { params });
	}
	// 获取互动信息
	interaction(params) {
		return this.$get("/interaction", { params });
	}
	// 操作日志
	log(params) {
		return this.$get("/zone", { params });
	}
	// 客户-流失
	runoff(cus_id) {
		return this.$get("/runoff", { params: { cus_id } });
	}
	// 最近一笔订单
	lastOrder(params) {
		return this.$get("/lastorder", { params });
	}
	// 回访添加
	addVisit(params) {
		return this.$post("/addvisit", params);
	}
	// 获取归属客户
	getBelong(params) {
		return this.$get("/getBelong", { params });
	}
	/**
	 * 部分客户调整提交
	 * @param String section_id  部门ID
	 * @param String user_id     员工ID
	 * @param String cus_ids     客户ID
	 */
	updateCus(params) {
		return this.$post("/updateCus", params, { silence: true });
	}

	/**
	 * 全部客户调整提交
	 * @param String old_section_id  旧的部门ID 原归属人
	 * @param String old_user_id     旧的员工ID原归属人
	 * @param String section_id  部门ID
	 * @param String user_id     员工ID
	 */
	updateCusAll(params) {
		return this.$post("/updateCusAll", params, { silence: true });
	}
	// 修改客户手机号
	editMobile(params) {
		return this.$post("/editMobile", params);
	}

	//售后客户回访列表
	cusVisitList({ size, date, bra_id = [], ...args }) {
		let params = {
			pagesize: size,
			bra_id: bra_id.join(),
			...args
		};
		if (date && date.length) {
			params.start_time = date[0];
			params.end_time = date[1];
		};
		return this.$get("/returnvisit", { params }).then(res => {
			return {
				list: res.data,
				pagination: {
					...params,
					size,
					total: res.total
				}
			};
		});
	}
	// 客户编辑 时标签列表
	tag(params) {
		return this.$get("/tag", { params });
	}
	// crm 客户标签列表
	tagLists(params) {
		return this.$get("/taglists", { params }).then((res) => {
			console.log(res);
			return {
				list: res.lists,
				pagination: {
					...params,
					total: res.total
				}
			};
		})
	}
	// crm 增加客户标签列表
	inctagLists(params) {
		return this.$post("/inctaglists", params);
	}
	// crm 修改客户标签列表
	editTagLists(params) {
		return this.$post("/edittaglists", params);
	}
	// crm 删除客户标签列表
	delTagLists(params) {
		return this.$post("/deltaglists", params);
	}
	//客诉
	compl(params) {
		return this.$post("/compl", params);
	}
	// 自定义更新客户信息
	customizeUpdate(params) {
		return this.$post('/customizeUpdate', params)
	}

	// 录系统
	clueQuickAdd(params) {
		return this.$post("/clueQuickAdd", params);
	}

}
export default Customer;
